package com.example.administrator.uis.view

import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import com.example.administrator.uis.bean.ZhuzhuangtuBean

/**
 * Created by Administrator on 2017/11/13 0013.
 */
class ZhuzhuangtuView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
    private var linepaint = Paint()
    private var zhuPaint = Paint()
    private val data = arrayListOf<ZhuzhuangtuBean>(ZhuzhuangtuBean("小红", 60f, Color.RED),
            ZhuzhuangtuBean("小名", 70f, Color.GREEN),
            ZhuzhuangtuBean("小丽", 90f, Color.YELLOW))

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        linepaint.style = Paint.Style.STROKE
        var path = Path()
        path.moveTo(50f, 0f)
        path.rLineTo(0f, 150f)
        for (i in 1..10) {
            path.rMoveTo(0f, -15f)
            path.rLineTo(5f, 0f)
            path.rMoveTo(-5f, 0f)
        }
        path.rMoveTo(0f, 150f)
        path.rLineTo(200f, 0f)
        path.rMoveTo(-180f, 0f)
        for (i in 0 until data.size) {
            var startX = 50 + 45f * (i + 1)
            var startY = 150f - data[i].yValue
            var rect = RectF(startX, startY, 45f * (i + 1) + 70, 150f)
//            var rect=RectF(15f*i,data[i].yValue,15f*i+10,0f)
            zhuPaint.color = data[i].color
            zhuPaint.style = Paint.Style.FILL
            canvas?.drawRect(rect, zhuPaint)
            zhuPaint.textSize = 10f
            canvas?.drawText(data[i].xValue, startX, 170f, zhuPaint);
//            path.rMoveTo(0f,-data[i].yValue)
//            path.rLineTo(10f,0f)
//            path.rMoveTo(10f,data[i].yValue)
        }
//        for (i in data){
//            var rectf=RectF(0f,0f,90f,90f)
//            path.addRect(rectf,Path.Direction.CW)
//            path.rMoveTo(15f,0f)
//            path.rLineTo(0f,5f)
//            path.rMoveTo(0f,-5f)
//
////            path.addRect()
//        }
        canvas?.drawPath(path, linepaint)

    }
}